package com.lh.microservice2.service.impl;

import com.lh.microservice2.service.RequestByRibbonService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @author lh
 * @Description:
 * @date 2021/3/26 16:27
 */
@Service
public class RequestByRibbonServiceImpl implements RequestByRibbonService {
	@Autowired // 默认按照类型注入,如果需要按照名字注入需要使用@Qualifier注解
	@Qualifier("ribbonRestTemplate")
	private RestTemplate restTemplate;

	@Override
	@HystrixCommand(fallbackMethod = "hiError")
	public String requestByRibbon(String name) {
		return restTemplate.getForObject("http://recall-project-microservice1/ribbon/ribbonTest?name=" + name, String.class);
	}

	public String hiError(String name) {
		return "hi," + name + ",sorry,error!";
	}
}
